/**
 * 
 */
package com.mynumnum.os9.system;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;

import com.mynumnum.cpu.Processor;

/**
 * @author hathaway3
 * The Kernel should implement all the OS9 calls as found in Nitros-9/OS-9
 * these methods will be called by each processor that is running a process
 * TODO Determine if this system call is case sensitive
 * 
 */
public class Kernel {
	private static ArrayList<Os9Process> processes = new ArrayList<Os9Process>();

	public Kernel() {
		// TODO Auto-generated constructor stub
	}
	/**
	 * <b>Compare Names - Compares two string for a match</b></br>
	 * OS9 F$CmpNam 103F 11</br>
	 * Entry Conditions:</br>
	 * B = length of string1</br>
	 * X = address of string1</br>
	 * Y = address of string2</br>
	 * Exit Conditions:</br>
	 * CC = carry clear if the strings match</br>
	 * 
	 * @param processor
	 * @param process
	 */
	public void os9F$CmpNam (Processor processor, Os9Process process) {
		// TODO write logic to compare strings
		String string1 = new String();
		try {
			string1 = new String(process.getProgramMemory(), Extra.getUnsigned(processor.getRegisters().getX()), Extra.getUnsigned(processor.getRegisters().getB()), "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		// Get the second string, the last byte of the string needs to have the MSB set
		String string2 = new String();
			
		// Get string from process memory
		// Compare
		// return Carry bit properly set
		if (string1.equals(string2)) {
			processor.getRegisters().setCCCarry(false);
		} else {
			processor.getRegisters().setCCCarry(true);	
		}
		
	}
	
}
